﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.ApplicationServer.Caching;

namespace Framework.DataCache
{
    public sealed class DistributedDataCacheItem
    {
        private readonly DataCacheItem _dataCacheItem;

        internal DistributedDataCacheItem(DataCacheItem dataCacheItem)
        {
            _dataCacheItem = dataCacheItem;
        }

        public string CacheName
        {
            get { return _dataCacheItem.CacheName; }
        }

        public string Key
        {
            get { return _dataCacheItem.Key; }
        }

        public string RegionName
        {
            get { return _dataCacheItem.RegionName; }
        }

        public ReadOnlyCollection<DistributedDataCacheTag> Tags
        {
            get
            {
                var list = _dataCacheItem.Tags.Select(dataCacheTag => new DistributedDataCacheTag(dataCacheTag)).ToList();
                var tags = new ReadOnlyCollection<DistributedDataCacheTag>(list);
                return tags;
            }
        }

        public TimeSpan Timeout
        {
            get { return _dataCacheItem.Timeout; }
        }

        public object Value
        {
            get { return _dataCacheItem.Value; }
        }

        public DistributedDataCacheItemVersion Version
        {
            get { return new DistributedDataCacheItemVersion(_dataCacheItem.Version); }
        }
    }
}
